from IPython.display import Image, display, Math, Latex
import os
import matplotlib
%matplotlib inline
matplotlib.use('Agg')
import matplotlib.pyplot as plt
plt.style.use('fivethirtyeight')
from datascience import *
import numpy as np
from scipy.fftpack import *
from mylib2 import * # basic helper functions
from conclusionlib import * # code to plot
Image(filename=DATA_PATH + '/img/control_group.png')
Profits are skewed to the left.
Most profit and loss occurred in the first 20 seconds of the trade.
Greater the ability for noise to return to its mean (zero) from significant deviations, greater the potential to make profits by trading futures alone.
DATA_PATH = 'C:/Users/admin/Desktop/Machine Learning'
pred = np.load(DATA_PATH + '/pred_classifier.npy') # predictions
obs = np.load(DATA_PATH + '/valid_classifier_y.npy') # observations
ones = [] # y_obs = 1
zeros = [] # y_obs = 0
for k in range(len(pred)):
if obs[k][0] < 0.01:
zeros.append(pred[k][0])
elif obs[k][0] > 0.99:
ones.append(pred[k][0])
plt.figure(figsize=(16, 4), dpi=80)
plt.hist(pred, bins=np.arange(0, 1.01, 0.01))
plt.xlabel('y_pred')
plt.ylabel('Frequency')
plt.show()
plt.figure(figsize=(16, 4), dpi=80)
plt.hist(zeros, bins=np.arange(0, 1.01, 0.01), alpha=0.6)
plt.hist(ones, bins=np.arange(0, 1.01, 0.01), alpha=0.6)
plt.xlabel('y_pred')
plt.ylabel('Frequency')
plt.legend(['y_obs = 0', 'y_obs = 1'])
plt.show()
plot_pnl('20190715', '/test_result_classifier_')
plot_pnl('20190715', '/test_result_classifier_dense_')
Image(filename=DATA_PATH + '/img/LSTM_classifier_sample_L_1.png')
Image(filename=DATA_PATH + '/img/LSTM_classifier_sample_L_2.png')
Image(filename=DATA_PATH + '/img/LSTM_classifier_sample_W_1.png')
Image(filename=DATA_PATH + '/img/LSTM_classifier_sample_W_2.png')
Image(filename=DATA_PATH + '/img/LSTM_classifier_sample_W_3.png')
pred = np.load(DATA_PATH + '/pred_regression.npy')
obs = np.load(DATA_PATH + '/valid_regression_y.npy')
r = find_r_of(pred, obs)
print('correlation coefficient = %lf\ncoefficient of determination = %lf' % (r, r ** 2))
plt.figure(figsize=(16, 9), dpi=100)
plt.xlabel('y_pred')
plt.ylabel('y_obs')
plt.scatter(pred, obs, 1.5)
plt.plot([-2, 4], [0, 0], lw=1, color='r')
plt.show()
plt.figure(figsize=(16,4), dpi=80)
plt.hist(pred, bins=np.arange(-5, 5, 0.1))
plt.show()
plt.figure(figsize=(16,4), dpi=80)
plt.hist(obs, bins=np.arange(-5, 5, 0.1))
plt.show()
plot_pnl_regression('20190628', '/test_result_regression_')
plot_pnl_regression('20190628', '/test_result_regression_DENSE_', detailed=False)
Consider , instead of which has fairly limited predictability.
Adjust X.shape = (LAGS, FEATURES), with longer lags in time but unevenly distributed ticks. Could also consider more features.
How to use trading volume data? Turning F_t to F_v reduces noise in futures price fluctuation.
How to use the value of basis?
*** How to adjust position during trading more strategically, representing an estimation of the likelihood of noise return.
How to implement asymetrical loss function? (Missing a profitable opportunity is better than making a failing trade, especially now P&L has a considerable left-skewed distribution)
Replace in X to , but correlation with will reduce.
Predict ?
Replace y in LSTM_regression with
The logic to generate samples and to backtest.